package com.hongfeng.support.controller.common;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class BaseController {

	protected Log log = LogFactory.getLog(this.getClass());

	/**
	 * 向页面发送json数据
	 * 
	 * @param response
	 * @param data
	 */
	protected void sendSuccResponse(HttpServletResponse response, String data) {
		try {
			response.setContentType("application/text;charset=UTF-8");
			response.getWriter().write(data);
		} catch (IOException e) {
			log.error("send response error", e);
		}
	}

	/**
	 * 向页面发送数据校验错误或是异常json数据
	 * 
	 * @param response
	 * @param msg
	 */
	protected void sendErrorResponse(HttpServletResponse response, String msg) {
		try {
			response.setContentType("application/text;charset=UTF-8");
			response.getWriter().write("{error:'" + msg + "'}");
		} catch (IOException e) {
			log.error("send response error", e);
		}
	}

}
